package cn.ctodb.im.server.conf;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.annotation.EnableKafka;

import java.util.UUID;

/**
 * All rights Reserved, Designed By www.ctodb.cn
 *
 * @version V1.0
 * @author: lichaohn@163.com
 * @Copyright: 2018 www.ctodb.cn Inc. All rights reserved.
 */
@Configuration
@EnableKafka
public class KafkaConfiguration implements InitializingBean {

    public static final String TOPIC_NAME = "TOPIC_NAME";

    @Autowired
    private ApplicationProperties applicationProperties;

    @Override
    public void afterPropertiesSet() {
        if (StringUtils.isBlank(applicationProperties.getKafkaTopic())) {
            String topic = UUID.randomUUID().toString();
            System.setProperty("application.kafka-topic", topic);
            applicationProperties.setKafkaTopic(topic);
        }
    }
}
